package com.shuoyue.ycgk.ui.course;

import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.BuildConfig;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.Course;
import com.shuoyue.ycgk.entity.course_teacher.AppPrice;
import com.shuoyue.ycgk.utils.GlideUtil;
import com.shuoyue.ycgk.views.dialog.common.HintDialog;

import java.util.List;

public class CourseAdapter extends AppBaseQuickAdapter<Course> {

    public CourseAdapter(@Nullable List<Course> data) {
        super(R.layout.item_course, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Course item) {
        helper.addOnClickListener(R.id.lay_all);
//        if(BuildConfig.DEBUG){
//            item.setActivePrice("21");
//            item.setActivePriceIntro("xxxxx");
//        }
        helper.setText(R.id.title, item.getName());
        helper.setText(R.id.info, Html.fromHtml((item.getBrief() == null ?
                "" : item.getBrief()) + (item.getStatus() == 1 ? "" : "<font color='#FF6633'> 上架中</font>")));
        //info.getTotalPerson() + "<font color='#333333'> 人已参加</font> "

        helper.setText(R.id.price, item.getIsFree() == 1 ? "免费" : ("￥" + item.getPrice()));
        helper.setText(R.id.learnNum, String.valueOf(item.getSalesVolume()));
        helper.setText(R.id.subNum, String.valueOf(item.getRestrictionVolume()));
        helper.setGone(R.id.lay_sub, item.getRestrictionVolume() != 0);
        GlideUtil.loadImage(mContext, item.getCover(), helper.getView(R.id.img));
        helper.setGone(R.id.info, item.getBrief() != null && item.getStatus() != 1);
        helper.setGone(R.id.free, item.getIsFree() == 1);
        helper.setGone(R.id.lay_price, item.getIsFree() != 1);

        if (item.getIsFree() != 1) {
            helper.setGone(R.id.lay_price_org, !TextUtils.isEmpty(item.getOriginalPrice()));
            helper.setGone(R.id.lay_price_vip, !TextUtils.isEmpty(item.getVipPrice()));
            helper.setGone(R.id.lay_price_activity, !TextUtils.isEmpty(item.getActivePrice()));

            helper.setText(R.id.price, "￥" + item.getPrice());
            helper.setText(R.id.price_org, "￥" + item.getOriginalPrice());
            helper.setText(R.id.vip_price, "￥" + item.getVipPrice());
            helper.setText(R.id.activity_price, "￥" + item.getActivePrice());

        } else {
            helper.setText(R.id.price, "");
            helper.setText(R.id.price_org, "");
            helper.setText(R.id.vip_price, "");
        }
        if (!TextUtils.isEmpty(item.getActivePriceIntro()))
            helper.getView(R.id.act_info).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    HintDialog hintDialog = new HintDialog(mContext, "活动详情", item.getActivePriceIntro());
                    hintDialog.show();
                }
            });
    }
}
